/*
package com.htht.job.executor.hander.downhandler;

import com.alibaba.fastjson.JSON;
import com.htht.job.core.biz.model.ReturnT;
import com.htht.job.core.biz.model.TriggerParam;
import com.htht.job.core.handler.IJobHandler;
import com.htht.job.core.handler.annotation.JobHandler;
import com.htht.job.core.util.ResultUtil;
import com.htht.job.executor.model.downupload.DownResult;
import com.htht.job.executor.model.ftp.Ftp;
import com.htht.job.executor.model.paramtemplate.DownParam;
import com.htht.job.executor.service.downupload.DownResultService;
import com.htht.job.executor.service.ftp.FtpService;
import com.htht.job.executor.util.downLoad.FtpUtil;

import org.apache.commons.lang3.StringUtils;
import org.htht.util.ApacheFtpUtil;
import org.htht.util.FileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


*/
/**
 * Created by zzj on 2018/1/9.
 *//*

@JobHandler(value = "downJobHandler")
@Service
public class DownJobHandler extends IJobHandler{
    @Autowired
    private FtpService ftpService;
    @Autowired
    private DownResultService downResultService;
    @Value("${tempFtpPath}")
    String tempFtpPath;
    @Override
    public ReturnT<String> execute(TriggerParam triggerParam) throws Exception {
            ResultUtil<String> result=new ResultUtil<String>();
            result=this.down(triggerParam,result);
            if(!result.isSuccess()){
                return new ReturnT<String>(ReturnT.FAIL_CODE, result.toString());
            }
            return ReturnT.SUCCESS;
    }

    public ResultUtil<String> down(TriggerParam triggerParam, ResultUtil<String> result){
    	DownResult downResult=new DownResult();
        try {
            DownParam downParam = JSON.parseObject(triggerParam.getModelParameters(),DownParam.class);
            //包括："原路径＋原名称＋","＋新路径＋新名称＋","+文件大小"
            String fileParam[]=triggerParam.getExecutorParams().split(",");
            String forFilePath=fileParam[0];//源文件的绝对地址
            String toFilePath=fileParam[1];//目标文件的绝对地址
            long fileSize = Long.parseLong(fileParam[2]);//文件的大小
            long fileDateLong = Long.parseLong(fileParam[3]);//文件的时间
            Date fileDate = new Date(fileDateLong); //文件的时间
            downResult.setDataTime(fileDate);
            downResult.setFileName(new File(toFilePath).getName());
            downResult.setRealFileName(new File(forFilePath).getName());
            downResult.setFileSize(fileSize);
            downResult.setFormat(toFilePath.substring(toFilePath.lastIndexOf(".")));
            downResult.setZt("1");//准备下载
    		downResult.setFilePath(new File(toFilePath).getParent());
    		downResult.setBz(downParam.getForSouceType()+"2"+downParam.getToSouceType());

            downResultService.saveDownResult(downResult);
            String extract="";
            boolean flag=false;
            if ("ftp".equals(downParam.getForSouceType())&&"file".equals(downParam.getToSouceType())) {//ftp下载到硬盘
                Ftp ftp = ftpService.getById(downParam.getForFtp());
                ApacheFtpUtil ftpUtil=new ApacheFtpUtil(ftp);
                if(ftpUtil.connectServer()){
                	long lRemoteSize = ftpUtil.downloadFTP(forFilePath, toFilePath, fileSize);
                	ftpUtil.closeServer();
                	if(lRemoteSize>=fileSize){
                		flag=true;
                	}
                }
            }else  if ("file".equals(downParam.getForSouceType())&&"file".equals(downParam.getToSouceType())) {//硬盘下载到硬盘
            	File localFile = new File(toFilePath);
				if(localFile.exists()){
					if(localFile.length() != fileSize){
						localFile.delete();
						FileUtil.copy(forFilePath,toFilePath+".tmp");
						File file2 = new File(toFilePath+".tmp");
						while (file2.exists() && file2.renameTo(file2)) {
							file2.renameTo(localFile);
						}
					}
				}
				else {
					FileUtil.copy(forFilePath,toFilePath+".tmp");
					File file2 = new File(toFilePath+".tmp");
					while (file2.exists() && file2.renameTo(file2)) {
						file2.renameTo(localFile);
					}
				}
				flag = true;
            }else if ("file".equals(downParam.getForSouceType())&&"ftp".equals(downParam.getToSouceType())){//硬盘上传到ftp
                Ftp ftp = ftpService.getById(downParam.getToFtp());
                ApacheFtpUtil ftpUtil=new ApacheFtpUtil(ftp);
                if(ftpUtil.connectServer()){
                	flag = ftpUtil.uploadFile(forFilePath, toFilePath);
                	ftpUtil.closeServer();
                	//存储下载路径
                	String toPath = ftp.getPath().replaceAll("\\\\", "/");
                	if(!toPath.endsWith("/")){
                		toPath+="/";
                	}
                }
            }else if ("ftp".equals(downParam.getForSouceType())&&"ftp".equals(downParam.getToSouceType())){
                Ftp forftp = ftpService.getById(downParam.getForFtp());
                Ftp toftp = ftpService.getById(downParam.getToFtp());
                ApacheFtpUtil forFtpUtil=new ApacheFtpUtil(forftp);
                File tempFile=new File(toFilePath);
                if(forFtpUtil.connectServer()){
                	long lRemoteSize = forFtpUtil.downloadFTP(forFilePath,tempFile.getAbsolutePath(), fileSize);
                	forFtpUtil.closeServer();
                }

                ApacheFtpUtil toFtpUtil=new ApacheFtpUtil(toftp);
                if(toFtpUtil.connectServer()){
                	long lRemoteSize = toFtpUtil.downloadFTP(tempFile.getAbsolutePath(), toFilePath, fileSize);
                	toFtpUtil.closeServer();
                	if(lRemoteSize>=fileSize){
                		flag=true;
                		//存储下载路径
                    	String toPath = toftp.getPath().replaceAll("\\\\", "/");
                    	if(!toPath.endsWith("/")){
                    		toPath+="/";
                    	}
                	}
                }
                tempFile.delete();

            }
            if (flag) {
            	downResult.setZt("0");
                downResultService.saveDownResult(downResult);
            }
        } catch (Exception e) {
            result.setErrorMessage("下载出错");
            downResult.setZt("2");
            downResultService.saveDownResult(downResult);
            throw new RuntimeException();
        }

        return result;
    }
}
*/
